package collector.core.config;

import java.util.List;

import net.apexcns.core.config.ConfigSupport;
import collector.core.TaskConstVO;

import com.thoughtworks.xstream.annotations.XStreamAlias;
import com.thoughtworks.xstream.annotations.XStreamImplicit;

/**
 * <pre>
 * Class : collector.config.ConfigModule / ConfigModule.java
 * 	Define Class Object : 각 실행 모듈에 대한 공통 설정 및 스케줄 에대한 설정을 담는다.
 * <br>
 * </pre>
 * @author ytjeong / apexcns,Inc.
 * @version 1.0
 * @see javadoc
 * @since 2012. 9. 14.
 */
@XStreamAlias("configModule")
public class ConfigModule extends ConfigSupport {
	/** <pre>
     * Definition of serialVersionUID : type of long
     * <br>
     * </pre>
     */
    private static final long serialVersionUID = 1361841270615779571L;

//	@SuppressWarnings("unused")
//	@XStreamOmitField
//	private static ConfigModule configModule;

	private long maxFileSize;
	private String fileNameExtension;
	private String delimiter;
	private String moduleLogPath;
	private String moduleJobStatePath;

	@XStreamImplicit(itemFieldName="moduleTask")
	private List<TaskConstVO> moduleTaskList;
	
//	private ConfigModule() {
//	}

	public static ConfigModule newInstance() {
		return getConfig(ConfigModule.class);
	}

	public String getConfigPath() {
		return getConfigBase() + "/conf/config-module.xml";
	}
	
	public void afterBind() {
	}

	/** <pre>
	 * Method : ConfigModule.getMaxFileSize()
	 * 	to get maxFileSize
	 * <br> 
	 * @return the maxFileSize : type of long
	 * </pre>
	 */
	public long getMaxFileSize() {
	    return maxFileSize;
	}

	/** <pre>
	 * Method : ConfigModule.setMaxFileSize()
	 * 	to set maxFileSize 
	 * <br> 
	 * @param maxFileSize : type of long
	 * </pre>
	 */
	public void setMaxFileSize(long maxFileSize) {
	    this.maxFileSize = maxFileSize;
	}

	/** <pre>
	 * Method : ConfigModule.getFileNameExtension()
	 * 	to get fileNameExtension
	 * <br> 
	 * @return the fileNameExtension : type of String
	 * </pre>
	 */
	public String getFileNameExtension() {
	    return fileNameExtension;
	}

	/** <pre>
	 * Method : ConfigModule.setFileNameExtension()
	 * 	to set fileNameExtension 
	 * <br> 
	 * @param fileNameExtension : type of String
	 * </pre>
	 */
	public void setFileNameExtension(String fileNameExtension) {
	    this.fileNameExtension = fileNameExtension;
	}

	/** <pre>
	 * Method : ConfigModule.getDelimiter()
	 * 	to get delimiter
	 * <br> 
	 * @return the delimiter : type of String
	 * </pre>
	 */
	public String getDelimiter() {
	    return delimiter;
	}

	/** <pre>
	 * Method : ConfigModule.setDelimiter()
	 * 	to set delimiter 
	 * <br> 
	 * @param delimiter : type of String
	 * </pre>
	 */
	public void setDelimiter(String delimiter) {
	    this.delimiter = delimiter;
	}
	
	/** <pre>
	 * Method : ConfigModule.getModuleLogPath()
	 * 	to get moduleLogPath
	 * <br> 
	 * @return the moduleLogPath : type of String
	 * </pre>
	 */
	public String getModuleLogPath() {
		return moduleLogPath;
	}

	/** <pre>
	 * Method : ConfigModule.setModuleLogPath()
	 * 	to set moduleLogPath
	 * <br> 
	 * @return the moduleLogPath : type of String
	 * </pre>
	 */
	public void setModuleLogPath(String moduleLogPath) {
		this.moduleLogPath = moduleLogPath;
	}

	/** <pre>
	 * Method : ConfigModule.getModuleJobStatePath()
	 * 	to get moduleJobStatePath
	 * <br> 
	 * @return the moduleJobStatePath : type of String
	 * </pre>
	 */
	public String getModuleJobStatePath() {
		return moduleJobStatePath;
	}

	/** <pre>
	 * Method : ConfigModule.setModuleJobStatePath()
	 * 	to set moduleJobStatePath
	 * <br> 
	 * @return the moduleJobStatePath : type of String
	 * </pre>
	 */
	public void setModuleJobStatePath(String moduleJobStatePath) {
		this.moduleJobStatePath = moduleJobStatePath;
	}

	/** <pre>
	 * Method : ConfigModule.getModuleTaskList()
	 * 	to get moduleTaskList
	 * <br> 
	 * @return the moduleTaskList : type of List<TaskConstVO>
	 * </pre>
	 */
	public List<TaskConstVO> getModuleTaskList( ) {
	    return moduleTaskList;
	}

	public TaskConstVO getModuleTask( String pJobID ) {
	    if ( null == pJobID ) return null;
	    for ( TaskConstVO mtVo : moduleTaskList ) {
	    	if ( pJobID.equals(mtVo.getTaskName()) ) return mtVo;
	    }
	    return null;
	}
	/** <pre>
	 * Method : ConfigModule.setModuleTaskList()
	 * 	to set moduleTaskList 
	 * <br> 
	 * @param moduleTaskList : type of List<TaskConstVO>
	 * </pre>
	 */
	public void setModuleTaskList(List<TaskConstVO> moduleTaskList) {
	    this.moduleTaskList = moduleTaskList;
	}
	
	/* (non-Javadoc)
	 * @see java.lang.Object#toString() 
	 * 
	 * Method : collector.config.ConfigModule.toString()
	 */
	@Override
	public String toString() {
	    StringBuilder builder = new StringBuilder();
	    builder.append("ConfigModule [");
	    builder.append("\n, maxFileSize=").append(maxFileSize);
	    builder.append("\n, fileNameExtension=").append(fileNameExtension);
	    builder.append("\n, delimiter=").append(delimiter);
	    builder.append("\n, moduleTaskList=").append(moduleTaskList);
	    builder.append("]");
	    return builder.toString();
	}

}
